/***********************************************************************/
/*  Copyright Amrita Research Labs, AVV                               */
/***********************************************************************/
/*                                                                     */
/*  FLASH_LPC21XX.H:  Header file for Philips LPC21XX                  */
/*                                                                     */
/***********************************************************************/
#ifndef __FLASH_LPC21XX_H__
#define __FLASH_LPC21XX_H__

// Flash programming definitions

#define FLASH_LPC21XX_SIGN_WORD_ADDR 0x7B000
#define FLASH_LPC21XX_SIGN_WORD_VALUE 0x12345678
#define FLASH_LPC21XX_DATA_SECTOR_ADDR 0x7B000
#define FLASH_LPC21XX_DATA_SECTOR_SIZE 4096
#define FLASH_LPC21XX_BLOCK_SIZE 32
#define FLASH_LPC21XX_MAX_BLOCKS 16
#define FLASH_LPC21XX_MAX_BLOCK_ADDR (FLASH_LPC21XX_DATA_SECTOR_ADDR + (FLASH_LPC21XX_BLOCK_SIZE * MAX_BLOCKS))
#define FLASH_LPC21XX_MAX_BUFFER_SIZE (FLASH_LPC21XX_BLOCK_SIZE * FLASH_LPC21XX_MAX_BLOCKS) 

#define FLASH_LPC21XX_INIT_DONE 0
#define FLASH_LPC21XX_PROGRAMMING_DONE 1
#define FLASH_LPC21XX_READ_DONE 2
#define FLASH_LPC21XX_ERASE_DONE 3
#define FLASH_LPC_SIGN_WORD_PRESENT 4
#define SIGN_WORD_WRITE_DONE 5

//#define FLASH_LPC21XX_BUFFER_TOO_LARGE -1/*-EMSGSZ*/
//#define FLASH_LPC21XX_BLOCK_NUM_ERROR -2 /*replace with -EINVAL*/

unsigned int flash_lpc21xx_init();
unsigned int flash_lpc21xx_write_sign_word();
int flash_lpc21xx_has_sign();
unsigned int flash_lpc21xx_erase (unsigned int, unsigned int);
unsigned int flash_lpc21xx_program (unsigned int , unsigned char *, unsigned int );
unsigned int flash_lpc21xx_get_secnum (unsigned int );
int flash_lpc21xx_read_block(int block_num, unsigned char *buf, int bufsize);
int flash_lpc21xx_write_block(int block_num, unsigned char *buf, int bufsize);
int flash_lpc21xx_erase_block(int block_num);

#endif
